package com.mayikt.classloader;

import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.ServiceLoader;

/**
 * @ClassName Test013
 * @Author 蚂蚁课堂余胜军 QQ644064779 www.mayikt.com
 * @Version V1.0
 **/
public class Test013 {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {

        Class<?> aClass = Class.forName("com.mysql.jdbc.Driver");
        Thread.currentThread().setContextClassLoader(Test013.class.getClassLoader());
        Connection root =
                DriverManager
                        .getConnection
                                (
                                        "jdbc:mysql://127.0.0.1:3306/mysql?characterEncoding=UTF-8",
                                        "root", "root");
//        System.out.println("mayikt");
//        ClassLoader.getSystemClassLoader().loadClass("sffag");
//        Thread.currentThread().setContextClassLoader(Test013.class.getClassLoader().getParent());
//        // 双亲委派原则 spi机制
//        ServiceLoader<Driver> loadedDrivers = ServiceLoader.load(Driver.class);
//        loadedDrivers.forEach((t) -> {
//            System.out.println(t);
//        });

        ClassLoader.getSystemClassLoader().loadClass("");
    }
}
